package com.hong.listener;

import lombok.Data;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * 管理Listener的类
 *
 * @Author HQT
 * @Date 2022/7/22 19:39
 */
@Data
public class ListenerManager {
    Map<Class<? extends Listener>, HashSet<Listener>> listenerSets = new HashMap<>();

    public boolean addListener(Class<? extends Listener> key, Listener value) {
        HashSet<Listener> listeners = listenerSets.get(key);
        if (listeners == null) {
            listeners = new HashSet<>();
            listenerSets.put(key, listeners);
        }
        return listeners.add(value);
    }
}
